package com.jx.lcs.datareport.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.SQLQuery;
import org.hibernate.type.StandardBasicTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.jx.lcs.datareport.entity.DataReport;
import com.jx.lcs.integral.entity.UserIntegral;
import com.tianyu.jty.common.persistence.HibernateDao;
import com.tianyu.jty.common.utils.DateUtils;

/** 
 * 数据报表DAO
 * @author JiaYY 
 * @date 2015年7月3日
 */
@Repository
public class DataReportDao extends HibernateDao<DataReport, String> {
	
	private static final Logger logger = LoggerFactory.getLogger(DataReportDao.class);

	/**
	 * 查询某日期前的累计注册用户数
	 * @param date 日期
	 * @return 数量
	 */
	public int findTotalRegistUserNum(String beginDate, String endDate) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from tb_user_info where 1=1");
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and createtime >= '").append(beginDate).append("'");
			}
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and createtime < '").append(endDate).append("'");
			}
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询某日期前的累计注册用户数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询某日期前的累计登录用户数
	 * @param date 日期
	 * @param os ios或安卓
	 * @return 数量
	 */
	public int findTotalLoginUserNum(String beginDate, String endDate, String os) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from tb_user_info t1, (select t.uid from tb_user_session t where 1=1");
			if(os != null && !"".equals(os)) {
				sb.append(" and t.os='").append(os).append("'");
			}
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and t.lastlogintime >= '").append(beginDate).append("'");
			}
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and t.lastlogintime < '").append(endDate).append("'");
			}
			sb.append(" group by t.uid) t2 where t1.uid=t2.uid");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询某日期前的累计登录用户数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询某日期的注册用户数
	 * @param date 日期
	 * @return 数量
	 */
	public int findRegistUserNum(String beginDate, String endDate) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from tb_user_info where 1=1");
			
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and createtime >= '").append(beginDate).append("'");
			}
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and createtime < '").append(endDate).append("'");
			}
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询某日期的注册用户数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询某日期的登录次数
	 * @param date 日期
	 * @param os ios或安卓
	 * @return 数量
	 */
	public int findLoginTimesNum(String beginDate, String endDate, String os) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from tb_user_session t where 1=1");
			if(os != null && !"".equals(os)) {
				sb.append(" and t.os='").append(os).append("'");
			}
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and t.lastlogintime >= '").append(beginDate).append("'");
			}
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and t.lastlogintime < '").append(endDate).append("'");
			}
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询某日期的登录次数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询某日期的登录用户数
	 * @param date 日期
	 * @param os ios或安卓
	 * @return 数量
	 */
	public int findLoginUserNum(String beginDate, String endDate, String os) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from (select t1.uid, count(*) num from (select t.uid, t.lastlogintime from tb_user_session t where 1=1");
			if(os != null && !"".equals(os)) {
				sb.append(" and t.os = '").append(os).append("'");
			}
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and t.lastlogintime >= '").append(beginDate).append("'");
			}
			if(!StringUtils.isBlank(beginDate)) {
				sb.append(" and t.lastlogintime < '").append(endDate).append("'");
			}
			sb.append(" ) t1 group by t1.uid) t2");
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询某日期的登录用户数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询某日期的新增用户数
	 * @param date 日期
	 * @param os ios或安卓
	 * @return 数量
	 */
	public int findNewUserNum(String beginDate, String endDate, String os) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from (select t.uid, min(t.lastlogintime) from tb_user_session t");
			if(os != null && !"".equals(os)) {
				sb.append(" where t.os = '").append(os).append("'");
			}
			sb.append(" group by t.uid having min(t.lastlogintime) between ?0 and ?1) t2");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询某日期的新增用户数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询产品代理次数
	 * @param date
	 * @param os
	 * @return
	 */
	public Map<String, Integer> findProductAgentTimesNum(String beginDate, String endDate, String os) {
		Map<String, Integer> result = new HashMap<String, Integer>();
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select t1.pcode, count(*) num from tb_product_agent t1, tc_product_info t2");
			if(os != null && !"".equals(os)) {
				sb.append(", (select ta.uid from tb_user_session ta, (select t.uid, max(t.lastlogintime) lastlogintime from tb_user_session t where t.lastlogintime < '").append(endDate).append("' group by t.uid) tb where ta.uid = tb.uid and ta.lastlogintime = tb.lastlogintime and ta.os = '").append(os).append("') t3");
			}
			sb.append(" where t1.pcode = t2.pcode");
			if(os != null && !"".equals(os)) {
				sb.append(" and t1.uid = t3.uid");
			}
			sb.append(" and t1.agentTime between ?0 and ?1 group by t1.pcode");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			
			sqlQuery.addScalar("pcode",StandardBasicTypes.STRING );
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			List<Object[]> list = (List<Object[]>) sqlQuery.list();
			Object[] obj = null;
			
			if(list != null && list.size() > 0) {
				for(int i=0; i<list.size(); i++) {
					obj = list.get(i);
					
					result.put((String)obj[0], (Integer)obj[1]);
				}
			}
		} catch(Exception e) {
			logger.error("--查询产品代理次数出现异常！", e);
		}
		
		return result;
	}
	
	/**
	 * 查询产品代理人数
	 * @param date
	 * @param os
	 * @return
	 */
	public Map<String, Integer> findProductAgentUserNum(String beginDate, String endDate, String os) {
		Map<String, Integer> result = new HashMap<String, Integer>();
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select t4.pcode, count(*) num from (select t1.pcode, t1.uid, count(*) from tb_product_agent t1, tc_product_info t2");
			if(os != null && !"".equals(os)) {
				sb.append(", (select ta.uid from tb_user_session ta, (select t.uid, max(t.lastlogintime) lastlogintime from tb_user_session t where t.lastlogintime < '").append(endDate).append("' group by t.uid) tb where ta.uid = tb.uid and ta.lastlogintime = tb.lastlogintime and ta.os = '").append(os).append("') t3");
			}
			sb.append(" where t1.pcode = t2.pcode");
			if(os != null && !"".equals(os)) {
				sb.append(" and t1.uid = t3.uid");
			}
			sb.append(" and t1.agentTime between ?0 and ?1 group by t1.pcode, t1.uid) t4 group by t4.pcode");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			
			sqlQuery.addScalar("pcode",StandardBasicTypes.STRING );
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			List<Object[]> list = (List<Object[]>) sqlQuery.list();
			Object[] obj = null;
			
			if(list != null && list.size() > 0) {
				for(int i=0; i<list.size(); i++) {
					obj = list.get(i);
					
					result.put((String)obj[0], (Integer)obj[1]);
				}
			}
		} catch(Exception e) {
			logger.error("--查询产品代理人数出现异常！", e);
		}
		return result;
	}
	
	/**
	 * 查询当前产品代理人数
	 * @param os
	 * @return
	 */
	public Map<String, Integer> findProductCurrAgentUserNum(String os) {
		Map<String, Integer> result = new HashMap<String, Integer>();
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select t4.pcode, count(*) num from (select t1.pcode, t1.uid, count(*) from tb_product_agent t1, tc_product_info t2");
			if(os != null && !"".equals(os)) {
				sb.append(", (select ta.uid from tb_user_session ta, (select t.uid, max(t.lastlogintime) lastlogintime from tb_user_session t group by t.uid) tb where ta.uid = tb.uid and ta.lastlogintime = tb.lastlogintime and ta.os = '").append(os).append("') t3");
			}
			sb.append(" where t1.pcode = t2.pcode");
			if(os != null && !"".equals(os)) {
				sb.append(" and t1.uid = t3.uid");
			}
			sb.append(" and t1.agentStatus='0' group by t1.pcode, t1.uid) t4 group by t4.pcode");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			
			sqlQuery.addScalar("pcode",StandardBasicTypes.STRING );
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			List<Object[]> list = (List<Object[]>) sqlQuery.list();
			Object[] obj = null;
			
			if(list != null && list.size() > 0) {
				for(int i=0; i<list.size(); i++) {
					obj = list.get(i);
					
					result.put((String)obj[0], (Integer)obj[1]);
				}
			}
		} catch(Exception e) {
			logger.error("--查询产品当前代理人数出现异常！", e);
		}
		return result;
	}
	
	/**
	 * 查询产品预约次数
	 * @param date
	 * @param os
	 * @return
	 */
	public Map<String, Integer> findProductOrderTimesNum(String beginDate, String endDate, String os) {
		Map<String, Integer> result = new HashMap<String, Integer>();
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select t1.pcode, count(*) num from tb_product_order t1, tc_product_info t2");
			if(os != null && !"".equals(os)) {
				sb.append(", (select ta.uid from tb_user_session ta, (select t.uid, max(t.lastlogintime) lastlogintime from tb_user_session t where t.lastlogintime < '").append(endDate).append("' group by t.uid) tb where ta.uid = tb.uid and ta.lastlogintime = tb.lastlogintime and ta.os = '").append(os).append("') t3");
			}
			sb.append(" where t1.pcode = t2.pcode");
			if(os != null && !"".equals(os)) {
				sb.append(" and t1.uid = t3.uid");
			}
			sb.append(" and t1.orderTime between ?0 and ?1 group by t1.pcode");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			
			sqlQuery.addScalar("pcode",StandardBasicTypes.STRING );
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			List<Object[]> list = (List<Object[]>) sqlQuery.list();
			Object[] obj = null;
			
			if(list != null && list.size() > 0) {
				for(int i=0; i<list.size(); i++) {
					obj = list.get(i);
					
					result.put((String)obj[0], (Integer)obj[1]);
				}
			}
		} catch(Exception e) {
			logger.error("--查询产品预约次数出现异常！", e);
		}
		return result;
	}
	
	/**
	 * 查询产品预约人数
	 * @param date
	 * @param os
	 * @return
	 */
	public Map<String, Integer> findProductOrderUserNum(String beginDate, String endDate, String os) {
		Map<String, Integer> result = new HashMap<String, Integer>();
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select t4.pcode, count(*) num from (select t1.pcode, t1.uid, count(*) from tb_product_order t1, tc_product_info t2");
			if(os != null && !"".equals(os)) {
				sb.append(", (select ta.uid from tb_user_session ta, (select t.uid, max(t.lastlogintime) lastlogintime from tb_user_session t where t.lastlogintime < '").append(endDate).append("' group by t.uid) tb where ta.uid = tb.uid and ta.lastlogintime = tb.lastlogintime and ta.os = '").append(os).append("') t3");
			}
			sb.append(" where t1.pcode = t2.pcode");
			if(os != null && !"".equals(os)) {
				sb.append(" and t1.uid = t3.uid");
			}
			sb.append(" and t1.orderTime between ?0 and ?1 group by t1.pcode, t1.uid) t4 group by t4.pcode");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			
			sqlQuery.addScalar("pcode",StandardBasicTypes.STRING );
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			List<Object[]> list = (List<Object[]>) sqlQuery.list();
			Object[] obj = null;
			
			if(list != null && list.size() > 0) {
				for(int i=0; i<list.size(); i++) {
					obj = list.get(i);
					
					result.put((String)obj[0], (Integer)obj[1]);
				}
			}
		} catch(Exception e) {
			logger.error("--查询产品预约人数出现异常！", e);
		}
		return result;
	}
	
	/**
	 * 查询产品预约人数
	 * @param date
	 * @param os
	 * @return
	 */
	public Map<String, Integer> findProductCurrOrderUserNum(String os) {
		Map<String, Integer> result = new HashMap<String, Integer>();
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select t4.pcode, count(*) num from (select t1.pcode, t1.uid, count(*) from tb_product_order t1, tc_product_info t2");
			if(os != null && !"".equals(os)) {
				sb.append(", (select ta.uid from tb_user_session ta, (select t.uid, max(t.lastlogintime) lastlogintime from tb_user_session t group by t.uid) tb where ta.uid = tb.uid and ta.lastlogintime = tb.lastlogintime and ta.os = '").append(os).append("') t3");
			}
			sb.append(" where t1.pcode = t2.pcode");
			if(os != null && !"".equals(os)) {
				sb.append(" and t1.uid = t3.uid");
			}
			sb.append(" and (t1.status='0' or t1.status='3') group by t1.pcode, t1.uid) t4 group by t4.pcode");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			
			sqlQuery.addScalar("pcode",StandardBasicTypes.STRING );
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			List<Object[]> list = (List<Object[]>) sqlQuery.list();
			Object[] obj = null;
			
			if(list != null && list.size() > 0) {
				for(int i=0; i<list.size(); i++) {
					obj = list.get(i);
					
					result.put((String)obj[0], (Integer)obj[1]);
				}
			}
		} catch(Exception e) {
			logger.error("--查询产品预约人数出现异常！", e);
		}
		return result;
	}
	
	/**
	 * 查询产品预约客户数
	 * @param date
	 * @param os
	 * @return
	 */
	public Map<String, Integer> findProductOrderCustomerNum(String beginDate, String endDate, String os) {
		Map<String, Integer> result = new HashMap<String, Integer>();
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select t4.pcode, count(*) num from (select t1.pcode, t1.cid, count(*) from tb_product_order t1, tc_product_info t2");
			if(os != null && !"".equals(os)) {
				sb.append(", (select ta.uid from tb_user_session ta, (select t.uid, max(t.lastlogintime) lastlogintime from tb_user_session t where t.lastlogintime < '").append(endDate).append("' group by t.uid) tb where ta.uid = tb.uid and ta.lastlogintime = tb.lastlogintime and ta.os = '").append(os).append("') t3");
			}
			sb.append(" where t1.pcode = t2.pcode");
			if(os != null && !"".equals(os)) {
				sb.append(" and t1.uid = t3.uid");
			}
			sb.append(" and t1.orderTime between ?0 and ?1 group by t1.pcode, t1.cid) t4 group by t4.pcode");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			
			sqlQuery.addScalar("pcode",StandardBasicTypes.STRING );
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			List<Object[]> list = (List<Object[]>) sqlQuery.list();
			Object[] obj = null;
			
			if(list != null && list.size() > 0) {
				for(int i=0; i<list.size(); i++) {
					obj = list.get(i);
					
					result.put((String)obj[0], (Integer)obj[1]);
				}
			}
		} catch(Exception e) {
			logger.error("--查询产品预约客户数出现异常！", e);
		}
		return result;
	}
	
	/**
	 * 查询产品预约客户数
	 * @param date
	 * @param os
	 * @return
	 */
	public Map<String, Integer> findProductCurrOrderCustomerNum(String os) {
		Map<String, Integer> result = new HashMap<String, Integer>();
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select t4.pcode, count(*) num from (select t1.pcode, t1.cid, count(*) from tb_product_order t1, tc_product_info t2");
			if(os != null && !"".equals(os)) {
				sb.append(", (select ta.uid from tb_user_session ta, (select t.uid, max(t.lastlogintime) lastlogintime from tb_user_session t group by t.uid) tb where ta.uid = tb.uid and ta.lastlogintime = tb.lastlogintime and ta.os = '").append(os).append("') t3");
			}
			sb.append(" where t1.pcode = t2.pcode");
			if(os != null && !"".equals(os)) {
				sb.append(" and t1.uid = t3.uid");
			}
			sb.append(" and (t1.status='0' or t1.status='3') group by t1.pcode, t1.cid) t4 group by t4.pcode");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			
			sqlQuery.addScalar("pcode",StandardBasicTypes.STRING );
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			List<Object[]> list = (List<Object[]>) sqlQuery.list();
			Object[] obj = null;
			
			if(list != null && list.size() > 0) {
				for(int i=0; i<list.size(); i++) {
					obj = list.get(i);
					
					result.put((String)obj[0], (Integer)obj[1]);
				}
			}
		} catch(Exception e) {
			logger.error("--查询产品预约客户数出现异常！", e);
		}
		return result;
	}
	
	/**
	 * 查询产品代理次数
	 * @param date
	 * @return
	 */
	public int findProductAgentTimesNumAll(String beginDate, String endDate) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from tb_product_agent t1, tc_product_info t2");
			sb.append(" where t1.pcode = t2.pcode");
			sb.append(" and t1.agentTime between ?0 and ?1");
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询产品代理次数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询产品代理人数
	 * @param date
	 * @return
	 */
	public int findProductAgentUserNumAll(String beginDate, String endDate) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from (select t1.uid, count(*) from tb_product_agent t1, tc_product_info t2");
			sb.append(" where t1.pcode = t2.pcode");
			sb.append(" and t1.agentTime between ?0 and ?1 group by t1.uid) t4");
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询产品代理人数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询产品预约次数
	 * @param date
	 * @return
	 */
	public int findProductOrderTimesNumAll(String beginDate, String endDate) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from tb_product_order t1, tc_product_info t2");
			sb.append(" where t1.pcode = t2.pcode");
			sb.append(" and t1.orderTime between ?0 and ?1");
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询产品预约次数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询产品预约人数
	 * @param date
	 * @return
	 */
	public int findProductOrderUserNumAll(String beginDate, String endDate) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from (select t1.uid, count(*) from tb_product_order t1, tc_product_info t2");
			sb.append(" where t1.pcode = t2.pcode");
			sb.append(" and t1.orderTime between ?0 and ?1 group by t1.uid) t4");
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询产品预约人数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询产品预约客户数
	 * @param date
	 * @return
	 */
	public int findProductOrderCustomerNumAll(String beginDate, String endDate) {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from (select t1.cid, count(*) from tb_product_order t1, tc_product_info t2");
			sb.append(" where t1.pcode = t2.pcode");
			sb.append(" and t1.orderTime between ?0 and ?1 group by t1.cid) t4");
			SQLQuery sqlQuery = createSQLQuery(sb.toString(), beginDate, endDate);
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询产品预约客户数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询产品当前代理人数
	 * @return
	 */
	public int findProductCurrAgentUserNumAll() {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from (select t1.uid, count(*) from tb_product_agent t1, tc_product_info t2");
			sb.append(" where t1.pcode = t2.pcode");
			sb.append(" and t1.agentStatus='0' group by t1.uid) t4");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询产品当前代理人数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询产品当前预约理财师数
	 * @return
	 */
	public int findProductCurrOrderUserNumAll() {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from (select t1.uid, count(*) from tb_product_order t1, tc_product_info t2");
			sb.append(" where t1.pcode = t2.pcode");
			sb.append(" and (t1.status='0' or t1.status='3') group by t1.uid) t4");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询产品当前预约理财师数出现异常！", e);
			return -1;
		}
	}
	
	/**
	 * 查询产品当前预约客户数
	 * @return
	 */
	public int findProductCurrOrderCustomerNumAll() {
		try{
			StringBuffer sb = new StringBuffer();
			sb.append("select count(*) num from (select t1.cid, count(*) from tb_product_order t1, tc_product_info t2");
			sb.append(" where t1.pcode = t2.pcode");
			sb.append(" and (t1.status='0' or t1.status='3') group by t1.cid) t4");
			
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--查询产品当前预约客户数出现异常！", e);
			return -1;
		}
	}
}
